import axios from 'axios'
import {setStorageItem} from "./auth";
import {message} from "antd";

const server = axios.create({
    timeout: 10000, // 请求超时时间ss
})
server.interceptors.request.use(config => {
    if (config.method === 'post') {
        config.headers = {
            'x-csrf-token': sessionStorage.getItem('csrf-token')
        }
    }
    return config
})
server.interceptors.response.use(config => {
    if (config.headers.tokenid) {
        setStorageItem('tokenId', config.headers.tokenid)
    }
    return config.data
}, error => {
    message.error(error.message)
    return Promise.reject(error)
})
export default server
